-- vertical_damage
-- create by wangy
-- 道具： 翻开整列地板，对整列怪物造成伤害

return {
    apply = function(source, target, classId, value)
        -- 传入攻击者信息
        local assailantInfo = {
            ["property_id"] = classId,
        };

        -- 道具伤害加成
        local damage = value;
        if PropertyM.query(classId, "target") ~= PROPERTY_SELF then
            local prop = PropM.combine(source, "property_damage", 1);
            damage = PropM.apply(prop, damage);
        end

        -- 4. 遍历怪物所在列
        local ret = {};
        local pos = target.dbase:query("pos");
        if not pos then
            pos = target:getOwner();
        end

        local coor = DungeonM.convertToCoor(pos);
        local y;
        local m;

        local cover = { };
        for y = 1, DUNGEON_HEIGHT do
            m = DungeonM.convertToPos(coor.x, y);
            table.insert(cover, 1, m);
        end

        for _, m in pairs(cover) do
            local grid = DungeonM.getGridByPos(m);

            -- 如果是未翻开的格子
            if  not grid:isOpened()  then
                grid:open();
            end

            -- 如果是未死亡的怪物
            if  grid:isMonster() and
                not grid.monster:isDead() then
                -- 修正伤害值
                local fixDamage = PropertyM.fixPropertyDamage(source, grid.monster, classId, damage);

                -- 先对目标造成伤害
                if ItemM.query(classId, "apply") == "damage_and_drop" then
                    -- 会掉落道具
                    CombatM.doDamage(source, grid.monster, fixDamage, 0, true, { assailantInfo = assailantInfo, });
                else
                    CombatM.doDamage(source, grid.monster, fixDamage, 0, false, { assailantInfo = assailantInfo, });
                end

                table.insert(ret, grid.monster);
            end
        end

        -- 抛出使用道具攻击事件
        EventMgr.fire(event.PROPERTY_ATTACK, { ["classId"] = classId, ["target"] = target, ["source"] = source, ["moreTarget"] = ret});
    end,
};
